
import { _decorator, Component, Node } from 'cc';
import Action3dManager, { Action3d, ActionMngType } from '../../Script/Common/Action3dManager';
import EventManager from '../../Script/Common/EventManager';
import { EventType } from '../../Script/GameSpecial/GameEventType';
import yyComponent from '../../Script/Common/yyComponent';
import GamePlatform from '../../Script/Platform/GamePlatform';
import { GamePlatformType } from '../../Script/Platform/GamePlatformType';
const { ccclass, property } = _decorator;

@ccclass('BtnNativeAd')
export class BtnNativeAd extends yyComponent {

    onLoad() {
        if (GamePlatform.Config.type != GamePlatformType.HeyGameOPPO
            && GamePlatform.Config.type != GamePlatformType.HeyGameVIVO) {
            this.node.active = false;
        } else {
            this.initAction();
            this.node.on(Node.EventType.TOUCH_START, this.onClick, this);
        }
    }

    onClick() {
        this.playClickBtn();
        EventManager.emit(EventType.Common.HeyGameSDK.clickNativeAd);
    }

    protected action: Action3d = null;
    protected initAction() {
        let s = this.node.scale.x + 0.15;//
        this.node.setScale(s, s, s);
        let d = 0.4;
        s += 0.2;
        let scale0 = Action3dManager.scaleTo(d, s, s, s);
        s -= 0.2;
        let scale1 = Action3dManager.scaleTo(d, s, s, s);
        let seq = Action3dManager.sequence(scale0, scale1);
        this.action = Action3dManager.repeatForever(seq);
    }
    onEnable() {
        Action3dManager.getMng(ActionMngType.UI).runAction(this.node, this.action);
    }
    onDisable() {
        Action3dManager.getMng(ActionMngType.UI).stopAllActions(this.node);
    }

}
